//
//  YJUserDefaultTool.m
//  YJB
//
//  Created by 中电大维 on 16/5/16.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "YJUserDefaultTool.h"
#import "YJKeychainTool.h"

@implementation YJUserDefaultTool
//读取登录状态
+ (BOOL)readLoginStatus
{
    id status = [[NSUserDefaults standardUserDefaults] objectForKey:@"loginStatus"];
    return [status boolValue];
}

+ (void)saveLoginStatus:(BOOL)status
{
    [[NSUserDefaults standardUserDefaults] setBool:status forKey:@"loginStatus"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)saveUserAccount:(NSString *)account
{
    [YJKeychainTool saveUserAccount:account];
}

+ (NSString *)readUserAccount
{
    return [YJKeychainTool readUserAccount];
}

+ (void)saveUserName:(NSString *)userName
{
    [YJKeychainTool saveUserName:userName];
}

+ (NSString *)readUserName
{
    return [YJKeychainTool readUserName];
}

+ (void)saveUserIconUrl:(NSString *)iconUrl
{
    [[NSUserDefaults standardUserDefaults] setObject:iconUrl forKey:@"iconUrl"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)readUserIconUrl
{
     return [[NSUserDefaults standardUserDefaults] stringForKey:@"iconUrl"];
}

+ (void)saveUserID:(NSString *)userID
{
    [[NSUserDefaults standardUserDefaults] setObject:userID forKey:@"userID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)readUserID
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"userID"];
  
}
+ (void)saveKeyID:(NSString *)keyID
{
    [[NSUserDefaults standardUserDefaults] setObject:keyID forKey:@"keyID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
 
}
+ (NSString *)readKeyID
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"keyID"];
}

+ (void)saveInviteCode:(NSString *)InviteCode
{
    NSString *key = [[self readUserID] stringByAppendingString:@"inviteCode"];
    [[NSUserDefaults standardUserDefaults] setObject:InviteCode forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

+ (NSString *)readInviteCode
{
    NSString *key = [[self readUserID] stringByAppendingString:@"inviteCode"];
    return [[NSUserDefaults standardUserDefaults] stringForKey:key];
}

+ (void)saveToken:(NSString *)Token
{
    [[NSUserDefaults standardUserDefaults] setObject:Token forKey:@"token"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

+ (NSString *)readToken
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"token"];
}

/* 卡号根据userID进行存取 */
+ (void)saveCardNumber:(NSString *)cardNum
{
    NSString *cardKey = [[self readUserID] stringByAppendingString:@"cardNum"];
    [[NSUserDefaults standardUserDefaults] setObject:cardNum  forKey:cardKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)readCardNumber
{
    NSString *cardKey = [[self readUserID] stringByAppendingString:@"cardNum"];
    return [[NSUserDefaults standardUserDefaults] stringForKey:cardKey];
}

+ (void)saveCardId:(NSString *)cardID
{
    
    [[NSUserDefaults standardUserDefaults] setObject:cardID forKey:@"cardID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)readCardID
{
   
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"cardID"];
}

+ (void)saveUserBindMessageCount:(int)count
{
        NSString *countKey = [[self readUserID] stringByAppendingString:@"count"];
    [[NSUserDefaults standardUserDefaults] setObject:@(count)  forKey:countKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (int )readBindCount
{
    NSString *countKey = [[self readUserID] stringByAppendingString:@"count"];
    return [[[NSUserDefaults standardUserDefaults] stringForKey:countKey] intValue];
}

+ (void)saveGuideMark:(BOOL)tag
{
    [[NSUserDefaults standardUserDefaults] setObject:@(tag) forKey:@"guideMark"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)readGuideMark
{
    return [[[NSUserDefaults standardUserDefaults] objectForKey:@"guideMark"] boolValue];

}

+ (void)saveDBVersion:(NSUInteger)version
{
    NSString *versionKey = [[self readUserID] stringByAppendingString:@"DBVersion"];
    [[NSUserDefaults standardUserDefaults] setObject:@(version) forKey:versionKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSUInteger)readDBVersion
{
    NSString *versionKey = [[self readUserID] stringByAppendingString:@"DBVersion"];
    return [[[NSUserDefaults standardUserDefaults] objectForKey:versionKey] unsignedIntegerValue];
}

+ (void)saveBalance:(NSString *)balance
{
    NSString *key = [[self readUserID] stringByAppendingString:@"balance"];
    [[NSUserDefaults standardUserDefaults] setObject:balance forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)readBalance
{
    NSString *key = [[self readUserID] stringByAppendingString:@"balance"];
    return [[NSUserDefaults standardUserDefaults] stringForKey:key];
}

+ (void)saveIsSilenceMode:(BOOL)isSilenceMode
{
    [[NSUserDefaults standardUserDefaults] setObject:@(isSilenceMode) forKey:@"silenceMode"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)readIsSilenceMode
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"silenceMode"];
}

@end
